﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataManager.DAL.SQL
{
    public class VasarlokMsSqlDAO : VasarlokDAO
    {
        private MsSqlUtils utils;

        public VasarlokMsSqlDAO(MsSqlUtils utils)
        {
            this.utils = utils;
        }

        public DataSet getMaxVasarlokId()
        {
            String sqlCommand = "select MAX(VasarloId) from Vasarlok";
            return utils.FillDataSetFromQuery(sqlCommand);
        }

        public DataSet nevek()
        {
            String sqlCommand = "select Nev from Vasarlok";
            return utils.FillDataSetFromQuery(sqlCommand);
        }

        public DataSet getIDFromName(String nev)
        {
            String sqlCommand = "select VasarloID from Vasarlok where Nev = '" + nev + "'";
            return utils.FillDataSetFromQuery(sqlCommand);
        }

        public DataSet getVasarlokAdatai(int Id)
        {
            String sqlCommand = "select Nev, Cim, Helyseg, EmailCim from Vasarlok where VasarloId = " + Id;
            return utils.FillDataSetFromQuery(sqlCommand);
        }

        public DataSet vasarlokAdatai()
        {
            String sqlCommand = "select * from Vasarlok";
            return utils.FillDataSetFromQuery(sqlCommand);
        }

        public void vasarloTorlese(int vasarloId)
        {
            String sqlCommand = "delete from Vasarlok where VasarloId = " + vasarloId;
            utils.ExecuteCommand(sqlCommand);
        }

        public void vasarlotFrissit(int vasarloID, string nev, string helyseg, string cim, string email)
        {
            String sqlCommand = "update Vasarlok set Nev = '" + nev +
                                                "', Cim = '" + cim + 
                                                "', Helyseg = '" + helyseg +
                                                "', EmailCim = '" + email +
                                                "' where VasarloId = " + vasarloID;
            utils.ExecuteCommand(sqlCommand);
        }

        public void vasarlotFrissitOptimista(int vasarloID, string nev, string helyseg, string cim, string email, string rnev, string rhelyseg, string rcim, string remail)
        {
            String sqlCommand = "update Vasarlok set Nev = '" + nev +
                                    "', Cim = '" + cim +
                                    "', Helyseg = '" + helyseg +
                                    "', EmailCim = '" + email +
                                    "' where VasarloId = " + vasarloID +
                                    " AND Nev = '" + rnev +
                                    "' AND Cim = '" + rcim +
                                    "' AND Helyseg = '" + rhelyseg +
                                    "' AND EmailCim = '" + remail + "'";
            utils.ExecuteCommand(sqlCommand);
        }

        public void vasarlotbeszur(int vasarloID, string nev, string helyseg, string cim, string email)
        {
            String sqlCommand = "INSERT INTO Vasarlok VALUES ( " + vasarloID + ", '" 
                                                                + nev + "', '"
                                                                + cim + "', '"
                                                                + helyseg + "', '"
                                                                + email + "' )";
            utils.ExecuteCommand(sqlCommand);
        }

    }
}
